﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SkyNote.Infrastructure.Helper
{
    public class EncryptHelper
    {
        public static string EncryptString(string sPlain, string sKey = "sintaotek@2012")
        {
            string result;
            if (string.IsNullOrEmpty(sPlain))
            {
                result = sPlain;
            }
            else
            {
                byte[] bytes = System.Text.Encoding.UTF8.GetBytes(sPlain);
                byte[] array = new byte[bytes.Length];
                byte[] bytes2 = System.Text.Encoding.UTF8.GetBytes(sKey);
                int num = 0;
                for (int i = 0; i < bytes.Length; i++)
                {
                    int num2 = (int)(bytes[i] ^ bytes2[num]);
                    array[i] = (byte)num2;
                    num = (num + 1) % bytes2.Length;
                }
                string text = System.Convert.ToBase64String(array);
                result = text;
            }
            return result;
        }
        public static string DecryptString(string sEncrypt, string sKey = "sintaotek@2012")
        {
            string result;
            if (string.IsNullOrEmpty(sEncrypt))
            {
                result = sEncrypt;
            }
            else
            {
                byte[] array = System.Convert.FromBase64String(sEncrypt);
                byte[] array2 = new byte[array.Length];
                byte[] bytes = System.Text.Encoding.UTF8.GetBytes(sKey);
                int num = 0;
                for (int i = 0; i < array.Length; i++)
                {
                    int num2 = (int)(array[i] ^ bytes[num]);
                    array2[i] = (byte)num2;
                    num = (num + 1) % bytes.Length;
                }
                string @string = System.Text.Encoding.UTF8.GetString(array2);
                result = @string;
            }
            return result;
        }
    }
}
